home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 13 / CU Amiga Magazine's Super CD-ROM 13 (1997)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1997-08].iso / CUCD / Graphics / Ghostscript / src / jpeg-6a / jcmarker.c < prev    next >
C/C++ Source or Header  |  1996-01-13  |  17KB  |  642 lines

  1. /*
  2.  * jcmarker.c
  3.  *
  4.  * Copyright (C) 1991-1996, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file contains routines to write JPEG datastream markers.
  9.  */
  10.  
  11. #define JPEG_INTERNALS
  12. #include "jinclude.h"
  13. #include "jpeglib.h"
  14.  
  15.  
  16. typedef enum {            /* JPEG marker codes */
  17.   M_SOF0  = 0xc0,
  18.   M_SOF1  = 0xc1,
  19.   M_SOF2  = 0xc2,
  20.   M_SOF3  = 0xc3,
  21.   
  22.   M_SOF5  = 0xc5,
  23.   M_SOF6  = 0xc6,
  24.   M_SOF7  = 0xc7,
  25.   
  26.   M_JPG   = 0xc8,
  27.   M_SOF9  = 0xc9,
  28.   M_SOF10 = 0xca,
  29.   M_SOF11 = 0xcb,
  30.   
  31.   M_SOF13 = 0xcd,
  32.   M_SOF14 = 0xce,
  33.   M_SOF15 = 0xcf,
  34.   
  35.   M_DHT   = 0xc4,
  36.   
  37.   M_DAC   = 0xcc,
  38.   
  39.   M_RST0  = 0xd0,
  40.   M_RST1  = 0xd1,
  41.   M_RST2  = 0xd2,
  42.   M_RST3  = 0xd3,
  43.   M_RST4  = 0xd4,
  44.   M_RST5  = 0xd5,
  45.   M_RST6  = 0xd6,
  46.   M_RST7  = 0xd7,
  47.   
  48.   M_SOI   = 0xd8,
  49.   M_EOI   = 0xd9,
  50.   M_SOS   = 0xda,
  51.   M_DQT   = 0xdb,
  52.   M_DNL   = 0xdc,
  53.   M_DRI   = 0xdd,
  54.   M_DHP   = 0xde,
  55.   M_EXP   = 0xdf,
  56.   
  57.   M_APP0  = 0xe0,
  58.   M_APP1  = 0xe1,
  59.   M_APP2  = 0xe2,
  60.   M_APP3  = 0xe3,
  61.   M_APP4  = 0xe4,
  62.   M_APP5  = 0xe5,
  63.   M_APP6  = 0xe6,
  64.   M_APP7  = 0xe7,
  65.   M_APP8  = 0xe8,
  66.   M_APP9  = 0xe9,
  67.   M_APP10 = 0xea,
  68.   M_APP11 = 0xeb,
  69.   M_APP12 = 0xec,
  70.   M_APP13 = 0xed,
  71.   M_APP14 = 0xee,
  72.   M_APP15 = 0xef,
  73.   
  74.   M_JPG0  = 0xf0,
  75.   M_JPG13 = 0xfd,
  76.   M_COM   = 0xfe,
  77.   
  78.   M_TEM   = 0x01,
  79.   
  80.   M_ERROR = 0x100
  81. } JPEG_MARKER;
  82.  
  83.  
  84. /*
  85.  * Basic output routines.
  86.  *
  87.  * Note that we do not support suspension while writing a marker.
  88.  * Therefore, an application using suspension must ensure that there is
  89.  * enough buffer space for the initial markers (typ. 600-700 bytes) before
  90.  * calling jpeg_start_compress, and enough space to write the trailing EOI
  91.  * (a few bytes) before calling jpeg_finish_compress.  Multipass compression
  92.  * modes are not supported at all with suspension, so those two are the only
  93.  * points where markers will be written.
  94.  */
  95.  
  96. LOCAL(void)
  97. emit_byte (j_compress_ptr cinfo, int val)
  98. /* Emit a byte */
  99. {
  100.   struct jpeg_destination_mgr * dest = cinfo->dest;
  101.  
  102.   *(dest->next_output_byte)++ = (JOCTET) val;
  103.   if (--dest->free_in_buffer == 0) {
  104.     if (! (*dest->empty_output_buffer) (cinfo))
  105.       ERREXIT(cinfo, JERR_CANT_SUSPEND);
  106.   }
  107. }
  108.  
  109.  
  110. LOCAL(void)
  111. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  112. /* Emit a marker code */
  113. {
  114.   emit_byte(cinfo, 0xFF);
  115.   emit_byte(cinfo, (int) mark);
  116. }
  117.  
  118.  
  119. LOCAL(void)
  120. emit_2bytes (j_compress_ptr cinfo, int value)
  121. /* Emit a 2-byte integer; these are always MSB first in JPEG files */
  122. {
  123.   emit_byte(cinfo, (value >> 8) & 0xFF);
  124.   emit_byte(cinfo, value & 0xFF);
  125. }
  126.  
  127.  
  128. /*
  129.  * Routines to write specific marker types.
  130.  */
  131.  
  132. LOCAL(int)
  133. emit_dqt (j_compress_ptr cinfo, int index)
  134. /* Emit a DQT marker */
  135. /* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */
  136. {
  137.   JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  138.   int prec;
  139.   int i;
  140.  
  141.   if (qtbl == NULL)
  142.     ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  143.  
  144.   prec = 0;
  145.   for (i = 0; i < DCTSIZE2; i++) {
  146.     if (qtbl->quantval[i] > 255)
  147.       prec = 1;
  148.   }
  149.  
  150.   if (! qtbl->sent_table) {
  151.     emit_marker(cinfo, M_DQT);
  152.  
  153.     emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  154.  
  155.     emit_byte(cinfo, index + (prec<<4));
  156.  
  157.     for (i = 0; i < DCTSIZE2; i++) {
  158.       /* The table entries must be emitted in zigzag order. */
  159.       unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  160.       if (prec)
  161.     emit_byte(cinfo, qval >> 8);
  162.       emit_byte(cinfo, qval & 0xFF);
  163.     }
  164.  
  165.     qtbl->sent_table = TRUE;
  166.   }
  167.  
  168.   return prec;
  169. }
  170.  
  171.  
  172. LOCAL(void)
  173. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  174. /* Emit a DHT marker */
  175. {
  176.   JHUFF_TBL * htbl;
  177.   int length, i;
  178.   
  179.   if (is_ac) {
  180.     htbl = cinfo->ac_huff_tbl_ptrs[index];
  181.     index += 0x10;        /* output index has AC bit set */
  182.   } else {
  183.     htbl = cinfo->dc_huff_tbl_ptrs[index];
  184.   }
  185.  
  186.   if (htbl == NULL)
  187.     ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  188.   
  189.   if (! htbl->sent_table) {
  190.     emit_marker(cinfo, M_DHT);
  191.     
  192.     length = 0;
  193.     for (i = 1; i <= 16; i++)
  194.       length += htbl->bits[i];
  195.     
  196.     emit_2bytes(cinfo, length + 2 + 1 + 16);
  197.     emit_byte(cinfo, index);
  198.     
  199.     for (i = 1; i <= 16; i++)
  200.       emit_byte(cinfo, htbl->bits[i]);
  201.     
  202.     for (i = 0; i < length; i++)
  203.       emit_byte(cinfo, htbl->huffval[i]);
  204.     
  205.     htbl->sent_table = TRUE;
  206.   }
  207. }
  208.  
  209.  
  210. LOCAL(void)
  211. emit_dac (j_compress_ptr cinfo)
  212. /* Emit a DAC marker */
  213. /* Since the useful info is so small, we want to emit all the tables in */
  214. /* one DAC marker.  Therefore this routine does its own scan of the table. */
  215. {
  216. #ifdef C_ARITH_CODING_SUPPORTED
  217.   char dc_in_use[NUM_ARITH_TBLS];
  218.   char ac_in_use[NUM_ARITH_TBLS];
  219.   int length, i;
  220.   jpeg_component_info *compptr;
  221.   
  222.   for (i = 0; i < NUM_ARITH_TBLS; i++)
  223.     dc_in_use[i] = ac_in_use[i] = 0;
  224.   
  225.   for (i = 0; i < cinfo->comps_in_scan; i++) {
  226.     compptr = cinfo->cur_comp_info[i];
  227.     dc_in_use[compptr->dc_tbl_no] = 1;
  228.     ac_in_use[compptr->ac_tbl_no] = 1;
  229.   }
  230.   
  231.   length = 0;
  232.   for (i = 0; i < NUM_ARITH_TBLS; i++)
  233.     length += dc_in_use[i] + ac_in_use[i];
  234.   
  235.   emit_marker(cinfo, M_DAC);
  236.   
  237.   emit_2bytes(cinfo, length*2 + 2);
  238.   
  239.   for (i = 0; i < NUM_ARITH_TBLS; i++) {
  240.     if (dc_in_use[i]) {
  241.       emit_byte(cinfo, i);
  242.       emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  243.     }
  244.     if (ac_in_use[i]) {
  245.       emit_byte(cinfo, i + 0x10);
  246.       emit_byte(cinfo, cinfo->arith_ac_K[i]);
  247.     }
  248.   }
  249. #endif /* C_ARITH_CODING_SUPPORTED */
  250. }
  251.  
  252.  
  253. LOCAL(void)
  254. emit_dri (j_compress_ptr cinfo)
  255. /* Emit a DRI marker */
  256. {
  257.   emit_marker(cinfo, M_DRI);
  258.   
  259.   emit_2bytes(cinfo, 4);    /* fixed length */
  260.  
  261.   emit_2bytes(cinfo, (int) cinfo->restart_interval);
  262. }
  263.  
  264.  
  265. LOCAL(void)
  266. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  267. /* Emit a SOF marker */
  268. {
  269.   int ci;
  270.   jpeg_component_info *compptr;
  271.   
  272.   emit_marker(cinfo, code);
  273.   
  274.   emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  275.  
  276.   /* Make sure image isn't bigger than SOF field can handle */
  277.   if ((long) cinfo->image_height > 65535L ||
  278.       (long) cinfo->image_width > 65535L)
  279.     ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  280.  
  281.   emit_byte(cinfo, cinfo->data_precision);
  282.   emit_2bytes(cinfo, (int) cinfo->image_height);
  283.   emit_2bytes(cinfo, (int) cinfo->image_width);
  284.  
  285.   emit_byte(cinfo, cinfo->num_components);
  286.  
  287.   for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  288.        ci++, compptr++) {
  289.     emit_byte(cinfo, compptr->component_id);
  290.     emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  291.     emit_byte(cinfo, compptr->quant_tbl_no);
  292.   }
  293. }
  294.  
  295.  
  296. LOCAL(void)
  297. emit_sos (j_compress_ptr cinfo)
  298. /* Emit a SOS marker */
  299. {
  300.   int i, td, ta;
  301.   jpeg_component_info *compptr;
  302.   
  303.   emit_marker(cinfo, M_SOS);
  304.   
  305.   emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  306.   
  307.   emit_byte(cinfo, cinfo->comps_in_scan);
  308.   
  309.   for (i = 0; i < cinfo->comps_in_scan; i++) {
  310.     compptr = cinfo->cur_comp_info[i];
  311.     emit_byte(cinfo, compptr->component_id);
  312.     td = compptr->dc_tbl_no;
  313.     ta = compptr->ac_tbl_no;
  314.     if (cinfo->progressive_mode) {
  315.       /* Progressive mode: only DC or only AC tables are used in one scan;
  316.        * furthermore, Huffman coding of DC refinement uses no table at all.
  317.        * We emit 0 for unused field(s); this is recommended by the P&M text
  318.        * but does not seem to be specified in the standard.
  319.        */
  320.       if (cinfo->Ss == 0) {
  321.     ta = 0;            /* DC scan */
  322.     if (cinfo->Ah != 0 && !cinfo->arith_code)
  323.       td = 0;        /* no DC table either */
  324.       } else {
  325.     td = 0;            /* AC scan */
  326.       }
  327.     }
  328.     emit_byte(cinfo, (td << 4) + ta);
  329.   }
  330.  
  331.   emit_byte(cinfo, cinfo->Ss);
  332.   emit_byte(cinfo, cinfo->Se);
  333.   emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  334. }
  335.  
  336.  
  337. LOCAL(void)
  338. emit_jfif_app0 (j_compress_ptr cinfo)
  339. /* Emit a JFIF-compliant APP0 marker */
  340. {
  341.   /*
  342.    * Length of APP0 block    (2 bytes)
  343.    * Block ID            (4 bytes - ASCII "JFIF")
  344.    * Zero byte            (1 byte to terminate the ID string)
  345.    * Version Major, Minor    (2 bytes - 0x01, 0x01)
  346.    * Units            (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm)
  347.    * Xdpu            (2 bytes - dots per unit horizontal)
  348.    * Ydpu            (2 bytes - dots per unit vertical)
  349.    * Thumbnail X size        (1 byte)
  350.    * Thumbnail Y size        (1 byte)
  351.    */
  352.   
  353.   emit_marker(cinfo, M_APP0);
  354.   
  355.   emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  356.  
  357.   emit_byte(cinfo, 0x4A);    /* Identifier: ASCII "JFIF" */
  358.   emit_byte(cinfo, 0x46);
  359.   emit_byte(cinfo, 0x49);
  360.   emit_byte(cinfo, 0x46);
  361.   emit_byte(cinfo, 0);
  362.   /* We currently emit version code 1.01 since we use no 1.02 features.
  363.    * This may avoid complaints from some older decoders.
  364.    */
  365.   emit_byte(cinfo, 1);        /* Major version */
  366.   emit_byte(cinfo, 1);        /* Minor version */
  367.   emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  368.   emit_2bytes(cinfo, (int) cinfo->X_density);
  369.   emit_2bytes(cinfo, (int) cinfo->Y_density);
  370.   emit_byte(cinfo, 0);        /* No thumbnail image */
  371.   emit_byte(cinfo, 0);
  372. }
  373.  
  374.  
  375. LOCAL(void)
  376. emit_adobe_app14 (j_compress_ptr cinfo)
  377. /* Emit an Adobe APP14 marker */
  378. {
  379.   /*
  380.    * Length of APP14 block    (2 bytes)
  381.    * Block ID            (5 bytes - ASCII "Adobe")
  382.    * Version Number        (2 bytes - currently 100)
  383.    * Flags0            (2 bytes - currently 0)
  384.    * Flags1            (2 bytes - currently 0)
  385.    * Color transform        (1 byte)
  386.    *
  387.    * Although Adobe TN 5116 mentions Version = 101, all the Adobe files
  388.    * now in circulation seem to use Version = 100, so that's what we write.
  389.    *
  390.    * We write the color transform byte as 1 if the JPEG color space is
  391.    * YCbCr, 2 if it's YCCK, 0 otherwise.  Adobe's definition has to do with
  392.    * whether the encoder performed a transformation, which is pretty useless.
  393.    */
  394.   
  395.   emit_marker(cinfo, M_APP14);
  396.   
  397.   emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  398.  
  399.   emit_byte(cinfo, 0x41);    /* Identifier: ASCII "Adobe" */
  400.   emit_byte(cinfo, 0x64);
  401.   emit_byte(cinfo, 0x6F);
  402.   emit_byte(cinfo, 0x62);
  403.   emit_byte(cinfo, 0x65);
  404.   emit_2bytes(cinfo, 100);    /* Version */
  405.   emit_2bytes(cinfo, 0);    /* Flags0 */
  406.   emit_2bytes(cinfo, 0);    /* Flags1 */
  407.   switch (cinfo->jpeg_color_space) {
  408.   case JCS_YCbCr:
  409.     emit_byte(cinfo, 1);    /* Color transform = 1 */
  410.     break;
  411.   case JCS_YCCK:
  412.     emit_byte(cinfo, 2);    /* Color transform = 2 */
  413.     break;
  414.   default:
  415.     emit_byte(cinfo, 0);    /* Color transform = 0 */
  416.     break;
  417.   }
  418. }
  419.  
  420.  
  421. /*
  422.  * This routine is exported for possible use by applications.
  423.  * The intended use is to emit COM or APPn markers after calling
  424.  * jpeg_start_compress() and before the first jpeg_write_scanlines() call
  425.  * (hence, after write_file_header but before write_frame_header).
  426.  * Other uses are not guaranteed to produce desirable results.
  427.  */
  428.  
  429. METHODDEF(void)
  430. write_any_marker (j_compress_ptr cinfo, int marker,
  431.           const JOCTET *dataptr, unsigned int datalen)
  432. /* Emit an arbitrary marker with parameters */
  433. {
  434.   if (datalen <= (unsigned int) 65533) { /* safety check */
  435.     emit_marker(cinfo, (JPEG_MARKER) marker);
  436.   
  437.     emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  438.  
  439.     while (datalen--) {
  440.       emit_byte(cinfo, *dataptr);
  441.       dataptr++;
  442.     }
  443.   }
  444. }
  445.  
  446.  
  447. /*
  448.  * Write datastream header.
  449.  * This consists of an SOI and optional APPn markers.
  450.  * We recommend use of the JFIF marker, but not the Adobe marker,
  451.  * when using YCbCr or grayscale data.  The JFIF marker should NOT
  452.  * be used for any other JPEG colorspace.  The Adobe marker is helpful
  453.  * to distinguish RGB, CMYK, and YCCK colorspaces.
  454.  * Note that an application can write additional header markers after
  455.  * jpeg_start_compress returns.
  456.  */
  457.  
  458. METHODDEF(void)
  459. write_file_header (j_compress_ptr cinfo)
  460. {
  461.   emit_marker(cinfo, M_SOI);    /* first the SOI */
  462.  
  463.   if (cinfo->write_JFIF_header)    /* next an optional JFIF APP0 */
  464.     emit_jfif_app0(cinfo);
  465.   if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  466.     emit_adobe_app14(cinfo);
  467. }
  468.  
  469.  
  470. /*
  471.  * Write frame header.
  472.  * This consists of DQT and SOFn markers.
  473.  * Note that we do not emit the SOF until we have emitted the DQT(s).
  474.  * This avoids compatibility problems with incorrect implementations that
  475.  * try to error-check the quant table numbers as soon as they see the SOF.
  476.  */
  477.  
  478. METHODDEF(void)
  479. write_frame_header (j_compress_ptr cinfo)
  480. {
  481.   int ci, prec;
  482.   boolean is_baseline;
  483.   jpeg_component_info *compptr;
  484.   
  485.   /* Emit DQT for each quantization table.
  486.    * Note that emit_dqt() suppresses any duplicate tables.
  487.    */
  488.   prec = 0;
  489.   for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  490.        ci++, compptr++) {
  491.     prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  492.   }
  493.   /* now prec is nonzero iff there are any 16-bit quant tables. */
  494.  
  495.   /* Check for a non-baseline specification.
  496.    * Note we assume that Huffman table numbers won't be changed later.
  497.    */
  498.   if (cinfo->arith_code || cinfo->progressive_mode ||
  499.       cinfo->data_precision != 8) {
  500.     is_baseline = FALSE;
  501.   } else {
  502.     is_baseline = TRUE;
  503.     for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  504.      ci++, compptr++) {
  505.       if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  506.     is_baseline = FALSE;
  507.     }
  508.     if (prec && is_baseline) {
  509.       is_baseline = FALSE;
  510.       /* If it's baseline except for quantizer size, warn the user */
  511.       TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  512.     }
  513.   }
  514.  
  515.   /* Emit the proper SOF marker */
  516.   if (cinfo->arith_code) {
  517.     emit_sof(cinfo, M_SOF9);    /* SOF code for arithmetic coding */
  518.   } else {
  519.     if (cinfo->progressive_mode)
  520.       emit_sof(cinfo, M_SOF2);    /* SOF code for progressive Huffman */
  521.     else if (is_baseline)
  522.       emit_sof(cinfo, M_SOF0);    /* SOF code for baseline implementation */
  523.     else
  524.       emit_sof(cinfo, M_SOF1);    /* SOF code for non-baseline Huffman file */
  525.   }
  526. }
  527.  
  528.  
  529. /*
  530.  * Write scan header.
  531.  * This consists of DHT or DAC markers, optional DRI, and SOS.
  532.  * Compressed data will be written following the SOS.
  533.  */
  534.  
  535. METHODDEF(void)
  536. write_scan_header (j_compress_ptr cinfo)
  537. {
  538.   int i;
  539.   jpeg_component_info *compptr;
  540.  
  541.   if (cinfo->arith_code) {
  542.     /* Emit arith conditioning info.  We may have some duplication
  543.      * if the file has multiple scans, but it's so small it's hardly
  544.      * worth worrying about.
  545.      */
  546.     emit_dac(cinfo);
  547.   } else {
  548.     /* Emit Huffman tables.
  549.      * Note that emit_dht() suppresses any duplicate tables.
  550.      */
  551.     for (i = 0; i < cinfo->comps_in_scan; i++) {
  552.       compptr = cinfo->cur_comp_info[i];
  553.       if (cinfo->progressive_mode) {
  554.     /* Progressive mode: only DC or only AC tables are used in one scan */
  555.     if (cinfo->Ss == 0) {
  556.       if (cinfo->Ah == 0)    /* DC needs no table for refinement scan */
  557.         emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  558.     } else {
  559.       emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  560.     }
  561.       } else {
  562.     /* Sequential mode: need both DC and AC tables */
  563.     emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  564.     emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  565.       }
  566.     }
  567.   }
  568.  
  569.   /* Emit DRI if required --- note that DRI value could change for each scan.
  570.    * If it doesn't, a tiny amount of space is wasted in multiple-scan files.
  571.    * We assume DRI will never be nonzero for one scan and zero for a later one.
  572.    */
  573.   if (cinfo->restart_interval)
  574.     emit_dri(cinfo);
  575.  
  576.   emit_sos(cinfo);
  577. }
  578.  
  579.  
  580. /*
  581.  * Write datastream trailer.
  582.  */
  583.  
  584. METHODDEF(void)
  585. write_file_trailer (j_compress_ptr cinfo)
  586. {
  587.   emit_marker(cinfo, M_EOI);
  588. }
  589.  
  590.  
  591. /*
  592.  * Write an abbreviated table-specification datastream.
  593.  * This consists of SOI, DQT and DHT tables, and EOI.
  594.  * Any table that is defined and not marked sent_table = TRUE will be
  595.  * emitted.  Note that all tables will be marked sent_table = TRUE at exit.
  596.  */
  597.  
  598. METHODDEF(void)
  599. write_tables_only (j_compress_ptr cinfo)
  600. {
  601.   int i;
  602.  
  603.   emit_marker(cinfo, M_SOI);
  604.  
  605.   for (i = 0; i < NUM_QUANT_TBLS; i++) {
  606.     if (cinfo->quant_tbl_ptrs[i] != NULL)
  607.       (void) emit_dqt(cinfo, i);
  608.   }
  609.  
  610.   if (! cinfo->arith_code) {
  611.     for (i = 0; i < NUM_HUFF_TBLS; i++) {
  612.       if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  613.     emit_dht(cinfo, i, FALSE);
  614.       if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  615.     emit_dht(cinfo, i, TRUE);
  616.     }
  617.   }
  618.  
  619.   emit_marker(cinfo, M_EOI);
  620. }
  621.  
  622.  
  623. /*
  624.  * Initialize the marker writer module.
  625.  */
  626.  
  627. GLOBAL(void)
  628. jinit_marker_writer (j_compress_ptr cinfo)
  629. {
  630.   /* Create the subobject */
  631.   cinfo->marker = (struct jpeg_marker_writer *)
  632.     (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  633.                 SIZEOF(struct jpeg_marker_writer));
  634.   /* Initialize method pointers */
  635.   cinfo->marker->write_any_marker = write_any_marker;
  636.   cinfo->marker->write_file_header = write_file_header;
  637.   cinfo->marker->write_frame_header = write_frame_header;
  638.   cinfo->marker->write_scan_header = write_scan_header;
  639.   cinfo->marker->write_file_trailer = write_file_trailer;
  640.   cinfo->marker->write_tables_only = write_tables_only;
  641. }
  642.